"""
Author: qiangqiang.cao
Copyright (c) 2023 - 2024, Shanghai Rural Commercial Bank Co., LTD. ALL rights reserved.
"""

import sys
import os

sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from dotenv import load_dotenv


from utils import ArgumentParser, ConfigLoader, LOG
from model import GLMModel, OpenAIModel, tongyiModel
from translator import PDFTranslator


if __name__ == "__main__":
    argument_parser = ArgumentParser()
    args = argument_parser.parse_arguments()
    config_loader = ConfigLoader(args.config)

    config = config_loader.load_config()

    model_name = args.openai_model if args.openai_model else config["TYModel"]["model"]
    base_url = args.openai_model if args.openai_model else config["TYModel"]["base_url"]
    api_key = (
        args.openai_api_key if args.openai_api_key else config["TYModel"]["api_key"]
    )

    model = tongyiModel(model=model_name, baseUrl=base_url, api_key=api_key)

    pdf_file_path = args.book if args.book else config["common"]["book"]
    file_format = (
        args.file_format if args.file_format else config["common"]["file_format"]
    )

    # 实例化 PDFTranslator 类，并调用 translate_pdf() 方法
    translator = PDFTranslator(model)
    translator.translate_pdf(pdf_file_path, file_format)
